/**
 *	@project:	kybernetes
 *	@author:	D.Toepel
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */
package dt.htwk.utilities;

import java.util.Hashtable;

import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;

import dt.htwk.core.Kybernetes;
import dt.htwk.panels.KCAdminPanel;

/**
 * <h3>Template</h3>
 *
 * @author DToepel
 *
 */
public class NaviModel extends DefaultTreeModel {
	
/* ****************************************************
 * Deklaration der Variablen und Komponenten
 * ***************************************************/

	/**
	 * serialVersionUID -- Standard: 1L
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 */
	private static Hashtable<String, String> lng;
	

/* ****************************************************
 * Aufruf des Konstruktors
 * ***************************************************/

	/**
	 * @param root
	 */
	public NaviModel(NaviNode root) {
		super(root);
	}

	
/* ****************************************************
 * PUBLIC - oeffentliche Methoden
 * ***************************************************/

	/**
	 * <h3>setNaviComponents</h3>
	 *
	 * @param id Kennung der
	 */
	public void setNaviComponents(Integer id){
		((DefaultMutableTreeNode) root).removeAllChildren();
		changeNaviComponents(id);
		this.reload();
	}

	/**
	 * <h3>setLanguageContent</h3>
	 *
	 * @param lng
	 */
	public static void setLanguageContent(Hashtable<String,String> lng){
		NaviModel.lng = lng;
	}

	
/* ****************************************************
 * PRIVATE - nicht-oeffentliche Methoden
 * ***************************************************/

	/**
	 * <h3>changeNaviComponents</h3>
	 *
	 * @param id
	 */
	private void changeNaviComponents(Integer id){
		switch (id){
		case 1 : 
			this.setRoot(getAdminNodes());
			break;
		case 2 : 
			this.setRoot(getRefereeNodes());
			break;
		case 3 : 
			this.setRoot(getUserNodes());
			break;
		case 4 : 
			this.setRoot(getGuestNodes());
			break;
		default : 
			this.setRoot(getAllNodes());
		}
	}
	
//	<group name="Navi-Panel">
//		<entity key="np-title">Navigation</entity>
//		<entity key="np-root">Kybernets Cup</entity>
//			<entity key="np-root-start">Startseite</entity>
//		<entity key="np-admin">Administration</entity>
//			<entity key="np-admin-prefs">Einstellungen</entity>
//			<entity key="np-admin-user">Benutzerverwaltung</entity>
//			<entity key="np-admin-sim">Simulation</entity>
//		<entity key="np-referee">Schiedsrichter</entity>
//		<entity key="np-user">Teilnehmer</entity>
//		<entity key="np-guest">Gast / Beobachter</entity>
//	</group>

	/**
	 * <h3>getAllNodes</h3>
	 *
	 * @return
	 */
	private NaviNode getAllNodes(){
		NaviNode rootNode = new NaviNode(lng.get("np-root"), null);
		rootNode.add(getAdminNodes());
		rootNode.add(getRefereeNodes());
		rootNode.add(getUserNodes());
		rootNode.add(getGuestNodes());
		
		return rootNode;
	}
	
	
	/**
	 * <h3>getAdminNodes</h3>
	 *
	 * @return
	 */
	private NaviNode getAdminNodes(){
		NaviNode rootNode = new NaviNode(lng.get("np-admin"), null);
		NaviNode rootChild,subChild;
		{
			rootChild = new NaviNode(lng.get("np-admin-prefs"), Kybernetes.AdminPanel);
			rootNode.add(rootChild);
			{
//				subChild = new NaviNode(lng.get("np-admin-sim"), KCAdminPanel.Simulation);
//				rootChild.add(subChild);
			}
			
			rootChild = new NaviNode(lng.get("np-admin-user"), Kybernetes.AdminPanel);
			rootNode.add(rootChild);
			
			rootChild = new NaviNode(lng.get("np-admin-sim"), Kybernetes.AdminPanel);
			rootNode.add(rootChild);
		}
		return rootNode;
	}
	
	
	/**
	 * <h3>getRefereeNodes</h3>
	 *
	 * @return
	 */
	private NaviNode getRefereeNodes() {
		NaviNode rootNode = new NaviNode(lng.get("np-referee"), null);
		NaviNode rootChild,subChild;
		{
			
		}
		return rootNode;
	}


	/**
	 * <h3>getUserNodes</h3>
	 *
	 * @return
	 */
	private NaviNode getUserNodes() {
		NaviNode rootNode = new NaviNode(lng.get("np-user"), null);
		NaviNode rootChild,subChild;
		{
			
		}
		return rootNode;
	}


	/**
	 * <h3>getGuestNodes</h3>
	 *
	 * @return
	 */
	private NaviNode getGuestNodes() {
		NaviNode rootNode = new NaviNode(lng.get("np-guest"), null);
		NaviNode rootChild,subChild;
		{
			
		}
		return rootNode;
	}


	class NaviTreeModelListener implements TreeModelListener {
        public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node;
            node = (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent());

            /*
             * If the event lists children, then the changed
             * node is the child of the node we've already
             * gotten.  Otherwise, the changed node and the
             * specified node are the same.
             */

                int index = e.getChildIndices()[0];
                node = (DefaultMutableTreeNode)(node.getChildAt(index));

            System.out.println("The user has finished editing the node.");
            System.out.println("New value: " + node.getUserObject());
        }
        public void treeNodesInserted(TreeModelEvent e) {
        }
        public void treeNodesRemoved(TreeModelEvent e) {
        }
        public void treeStructureChanged(TreeModelEvent e) {
        }
    }


}
